﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MachineLearning;

namespace winelist
{
    class Program
    {
        public static double dist1d(object a, object b)
        {
            double ad = (double)a;
            double bd = (double)b;
            return Math.Abs(ad - bd);
        }

        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("\nUsage: winelist.exe winelist.txt\n");
                Console.WriteLine("This program tests the performance of rank knn using winelist data from the machine learning repository\n");
                return;
            }

            var reader = new StreamReader(File.OpenRead(args[0]));
            
            bool firstLine = true;
            var fixedAcidity = new List<double>();
            
            var lines = new List<string>();
            while (!reader.EndOfStream)
            {
                if (!firstLine)
                {
                    lines.Add(reader.ReadLine());
                }
                else
                {
                    firstLine = false;
                }
            }

            int n = lines[0].Split(';').Length;
            var data = new List<object[]>();

            for (int i = 0; i < n; i++)
            {
                var d = new object[lines.Count];
                data.Add(d);
            }

            int[] labels = new int[lines.Count];

            for (int j = 0; j < lines.Count; j++)
            {
                var entries = lines[j].Split(';');
                for(int i = 0; i < entries.Length - 1; i++)
                {
                    var column = data[i];
                    column[j] = Double.Parse(entries[i]);
                }
                labels[j] = Int32.Parse(entries[entries.Length - 1]);
            }

            var distanceFunctions = new List<Func<object, object, double>>();
            for (int i = 0; i < n - 1; i++)
            {
                distanceFunctions.Add(dist1d);
            }
            
            var knn = new RankKNN(data, labels, distanceFunctions, null);

            // Split into train/test

            // See how we get on

        }
    }
}
